<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
        类字段
        1. 优点：简洁，无需显式定义constructor
        2. 确定：灵活度不够，无法通过外部传参
      */
      class Person {
        username = "jack";
        age = 20;
        constructor(a, b) {
          this.firstName = a;
          this.lastName = b;
        }
      }
      // constructor()
      const p1 = new Person("wang", "hong");
      console.log(p1);
    </script>
  </body>
</html>
